"""join()函数，主进程等待子进程运行结束后，才能继续往下执行"""
"""terminate()函数，强制结束子进程的运行

子进程传递参数，可以传递不定长参数、关键字参数"""
from multiprocessing import Process
import os
import time


def process_run(name, *args, **kwargs):
    print("Child process --1")
    print("Child process running, name={}, args={}, kwargs={}".format(name, args, kwargs))
    for i in range(10):
        print(i)
        time.sleep(0.5)
    print("Child process end")


if __name__ == '__main__':
    print("Parent process --2")
    # 给子进程指定函数传递参数
    p = Process(target=process_run, args=("laozhao", "帅哥", 18), kwargs={"addr": "USA"}, name="Child-1")

    p.start()  # 开启子进程
    print("Child process's name is %s" % p.name)
    time.sleep(4)

    # 等待子进程结束后才能往下执行
    # p.join()

    # 不管子进程有没结束，强行终止子进程
    p.terminate()
    print("Chile process --1 has forced termination")
